<header class="header">
    <div class="fix_nav">
        <div class="nav_inner">
            <a class="nav-left back-icon" href="javascript:goback();">返回</a>
            <div class="tit">绑定手机号码</div>
        </div>
    </div>
</header>
<div class="container tb_box">
    <form id="form1" action="#" method="post">
        <p>
        </p>
        <div class="alert alert-info alert-dismissable">
            您还未绑定手机号，第一次查询我的卡券需要先绑定手机号码
        </div>
        <div class="panel panel-success">
            <div class="panel-body">

                <div class="form-group">
                    <input placeholder="手机号码" class="form-control" id="mobileNum" />
                </div>
                <div class="form-group">
                    <div class="row">
                        <div class="col-sm-8 col-xs-6 pr0">
                            <input type="text" name="smsCode" class="form-control" id="smsCode" placeholder="请输入验证码">
                        </div>
                        <div class="col-sm-4 col-xs-6">
                            <button type="button" class="form-control btn-sm btn-primary" id="getSmsCode" >获取验证码</button>
                        </div>
                    </div>
                </div>

                <button class="btn btn-warning btn-block" type="button" id="submit">提  交</button>
            </div>
        </div>
    </form>
</div>
<script>

    var count = 30;
    var interval;
    var getSmsCodeBtn = $("#getSmsCode");
    function countDown(){

        if(count == 0){
            window.clearInterval(interval);
            getSmsCodeBtn.prop('disabled',false).text('获取验证码');
            return false;
        }
        getSmsCodeBtn.text('重新获取'+count);
        count--;
    }

    $(document).ready(function(){


        getSmsCodeBtn.click(function(){

            var mobileNum = $.trim($("#mobileNum").val());
            if(mobileNum == ''){

                floatNotify.simple('请输入您的手机号码!');
                return false;
            }

            var $this = $(this);
            $this.prop('disabled',true);
            $.post('/member/index/getSmsCode',{mobileNum:mobileNum},function(resp){
                if(resp.status == 1){
                    floatNotify.simple(resp.msg);
                    count = 30;
                    interval = setInterval('countDown()',1000);
                }else{
                    $this.prop('disabled',false);
                }
            },'json')
        })

        $("#submit").click(function(){

            var mobileNum = $.trim($("#mobileNum").val());
            if(mobileNum == ''){

                floatNotify.simple('请输入您的手机号码！');
                return false;
            }
            var smsCode = $.trim($("#smsCode").val());
            if(smsCode == ''){

                floatNotify.simple('请输入验证码！');
                return false;
            }
            var $this = $(this);
            $this.prop('disabled',true);
            $.post('/member/info/setMobile',{mobileNum:mobileNum,smsCode:smsCode},function(resp){
                floatNotify.simple(resp.msg);
                if(resp.status == 1){
                    setTimeout(function(){
                        window.location = '/member/index/barcode.html';
                    },1000)
                }
            },'json').always(function(){
                $this.prop('disabled',false);
            })
        })
    });
</script>